﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualTournaments.Business.Tournaments;
using VirtualTournaments.Business.Users;

namespace VirtualTournaments.Business.Bets
{
    /// <summary>
    /// Maneja las apuestas de un partido
    /// </summary>
    public class ThreeWaysBetType : BetType
    {
        Match _match;

        /// <summary>
        /// El partido sobre el cual se apuesta
        /// </summary>
        public Match Match { get { return _match; } }

        public ThreeWaysBetType(Match match)
            : base(match)
        {
            _match = match;
        }

        protected override BetTarget[] CreateAllAvaliableBetTargets(ICompetition competition)
        {
            return new BetTarget[]{
                new ThreeWaysBetTarget((Match)competition, MatchWinningTeam.Local),
                new ThreeWaysBetTarget((Match)competition, MatchWinningTeam.Draw),
                new ThreeWaysBetTarget((Match)competition, MatchWinningTeam.Visitor)
            };
        }

        public ThreeWaysBetTarget GetResultByWinningTeam(MatchWinningTeam prediction)
        {
            foreach (var item in this.BetTargets)
            {
                if (((ThreeWaysBetTarget)item).ExpectedResult.CompareTo(prediction) == 0)
                {
                    return (ThreeWaysBetTarget)item;
                }
            }
            return null;
        }
    }
}
